package com.transaction.simulate.service.impl;

import com.transaction.common.base.PageInfo;
import com.transaction.common.util.PageUtil;
import com.transaction.simulate.mapper.DictMapper;
import com.transaction.simulate.model.dto.Dict;
import com.transaction.simulate.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictServiceImpl implements DictService {

    @Autowired
    private DictMapper dictMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Dict> getDictInfo(Dict dict, PageInfo pageInfo) {
        PageUtil.StartPage(pageInfo);
        List<Dict> parentDict = dictMapper.getRootDictInfo(pageInfo,dict);
        parentDict.forEach(v->{
            List<Dict> children = dictMapper.getDictInfoByParentId(v.getId());
            v.setChildren(children);
        });
        return parentDict;
    }
}
